package fx.mine.active.component;

import fx.mine.active.component.bbs.BBSPane;
import fx.mine.active.component.blog.BlogPane;
import fx.mine.active.component.douyin.DouyinPane;
import fx.mine.active.component.english.EnglishPane;
import fx.mine.active.component.github.GithubPane;
import fx.mine.active.component.music.MusicPane;
import fx.mine.active.component.nav.NavPane;
import fx.mine.active.component.news.NewsPane;
import fx.mine.active.component.notebook.NotePane;
import fx.mine.active.component.stock.StockPane;
import fx.mine.active.component.translate.TranslatePane;
import javafx.collections.ObservableList;
import javafx.scene.Node;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.StackPane;
import lombok.extern.log4j.Log4j2;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

@Log4j2
public class MainScene extends StackPane {
    private static final Map<ScenePaneEnum, AnchorPane> CACHE_PANE_MAP = new HashMap<>();

    public MainScene() {
        AnchorPane.setBottomAnchor(this, 0.0);
        AnchorPane.setRightAnchor(this, 0.0);
        AnchorPane.setLeftAnchor(this, 250.0);
        AnchorPane.setTopAnchor(this, 50.0);

        double width = getWidth();
        double height = getHeight();
        ObservableList<Node> children = getChildren();

        var musicPane = new MusicPane(width, height);
        var navPane = new NavPane(width, height);
        var blogPane = new BlogPane(width, height);
        var notePane = new NotePane(width, height);
        var bbsPane = new BBSPane(width, height);
        var newsPane = new NewsPane(width, height);
        var stockPane = new StockPane(width, height);
        var englishPane = new EnglishPane(width, height);
        var douyinPane = new DouyinPane(width, height);
        var githubPane = new GithubPane(width, height);
        var translatePane = new TranslatePane(width, height);

        registered(ScenePaneEnum.MUSIC_PANE, musicPane);
        registered(ScenePaneEnum.NAV_PANE, navPane);
        registered(ScenePaneEnum.BLOG_PANE, blogPane);
        registered(ScenePaneEnum.NOTE_PANE, notePane);
        registered(ScenePaneEnum.BBS_PANE, bbsPane);
        registered(ScenePaneEnum.NEWS_PANE, newsPane);
        registered(ScenePaneEnum.STOCK_PANE, stockPane);
        registered(ScenePaneEnum.ENGLISH_PANE, englishPane);
        registered(ScenePaneEnum.DOUYIN_PANE, douyinPane);
        registered(ScenePaneEnum.TRANSLATE_PANE, translatePane);
        registered(ScenePaneEnum.GITHUB_PANE, githubPane);

        getStyleClass().add("mainScene");
        getStylesheets().add(getClass().getResource("/css/mainScene.css").toExternalForm());
    }

    public void registered(ScenePaneEnum key, AnchorPane o) {
        CACHE_PANE_MAP.put(key, o);
        getChildren().add(o);
    }

    public static Optional<AnchorPane> getByPaneEnum(ScenePaneEnum paneEnum) {
        AnchorPane anchorPane = CACHE_PANE_MAP.get(paneEnum);
        return Optional.ofNullable(anchorPane);
    }

    enum ScenePaneEnum {
        MUSIC_PANE,
        NAV_PANE,
        BLOG_PANE,
        NOTE_PANE,
        STOCK_PANE,
        BBS_PANE,
        ENGLISH_PANE,
        NEWS_PANE,
        DOUYIN_PANE,
        GITHUB_PANE,
        TRANSLATE_PANE,
    }


}
